#ifndef PROFILE_H_INCLUDED
#define PROFILE_H_INCLUDED

/************************************************************************

								Heroes IV
					  Copyright 1998, The 3DO Company

	------------------------------------------------------------------
  							 profile.h

	$Header: /heroes4/Game/profile.h $

	$NoKeywords: $

 ************************************************************************/

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

#include "format_string.h"
// profiling classes. "t_profile_marker" objects must always be static.

class t_profile_marker
{
public:
	t_profile_marker( std::string const& label, std::string const& line );

	char const* get_file_line() const;
	const char* get_label() const;
	long		get_hits() const;
	long		get_time_total() const;
	void		update( long new_time );
protected:
	std::string m_file_line;
	std::string m_label;
	long		m_hits;
	long		m_time_total;
};

#define declare_timer( name, msg )  static t_profile_marker name##_marker( msg, FILE_LINE_STRING ); \
                                    t_profile_timer name( name##_marker )

inline char const* t_profile_marker::get_file_line() const
{
	return m_file_line.c_str();
}

inline const char* t_profile_marker::get_label() const
{
	return m_label.c_str();
}

inline long t_profile_marker::get_hits() const
{
	return m_hits;
}

inline long t_profile_marker::get_time_total() const
{
	return m_time_total;
}


class t_profile_timer
{
public:
	t_profile_timer( t_profile_marker& new_marker, bool start = true );
	~t_profile_timer();

	void start();
	void stop();

protected:
	t_profile_marker& m_marker;

	int  m_start_time;
	bool m_running;
};


void dump_profile_markers(); // dump profiling results to debug output.
void enable_profiling( bool arg = true );
bool profiling_is_enabled();


#endif